/**
 *   FUSE-J: Java bindings for FUSE (Filesystem in Userspace by Miklos Szeredi (mszeredi@inf.bme.hu))
 *
 *   Copyright (C) 2003 Peter Levart (peter@select-tech.si)
 *
 *   This program can be distributed under the terms of the GNU LGPL.
 *   See the file COPYING.LIB
 */

package fuse;

import fuse.util.Log;


public class FuseMount
{
   private static final Log log = new Log(FuseMount.class);

   static
   {
      System.loadLibrary("javafs");
   }

   private FuseMount()
   {
      // no instances
   }


   //
   // compatibility API

   public static void mount(String[] args, Filesystem1 filesystem1) throws Exception
   {
      mount(args, new Filesystem1ToFilesystemAdapter(filesystem1));
   }

   //
   // prefered String level API

   public static void mount(String[] args, Filesystem filesystem) throws Exception
   {
      mount(args, new FilesystemToFuseFSAdapter(filesystem));
   }

   //
   // byte level API

   public static void mount(String[] args, FuseFS fuseFS) throws Exception
   {
      ThreadGroup threadGroup = new ThreadGroup(Thread.currentThread().getThreadGroup(), "FUSE Threads");
      threadGroup.setDaemon(true);

      log.info("Mounting filesystem");

      mount(args, fuseFS, threadGroup);

      log.info("Filesystem is unmounted");

      int n = threadGroup.activeCount();
      log.debug("ThreadGroup(\"" + threadGroup.getName() + "\").activeCount() = " + n);

      Thread[] threads = new Thread[n];
      threadGroup.enumerate(threads);
      for (int i = 0; i < threads.length; i++)
      {
         log.debug("thread[" + i + "] = " + threads[i] + ", isDaemon = " + threads[i].isDaemon());
      }
   }


   private static native void mount(String[] args, FuseFS fuseFS, ThreadGroup threadGroup) throws Exception;
}
